package org.dtrd.modules.record.entity.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.extern.slf4j.Slf4j;
import org.dtrd.common.util.DateUtils;
import org.dtrd.modules.record.entity.bean.HeightBean;
import org.dtrd.modules.util.SchemeUtil;

import javax.persistence.*;
import java.text.ParseException;
import java.util.Date;

@Slf4j
@Table(name = "dtrd_ent_rd_signin_height_weight")
public class DtrdEntRdSigninHeightWeight {
    @Id
    @Column(name = "data_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(type = IdType.AUTO)
    private Integer dataId;

    @Column(name = "patient_id")
    private Integer patientId;

    /**
     * 记录日期
     */
    @Column(name = "record_date")
    private Date recordDate;

    @Column(name = "record_type")
    private Integer recordType;

    /**
     * 测量时间
     */
    @Column(name = "record_time")
    private Date recordTime;

    /**
     * 身高
     */
    @Column(name = "height_weight_height")
    private Float heightWeightHeight;

    /**
     * 体重
     */
    @Column(name = "height_weight_weight")
    private Float heightWeightWeight;

    /**
     * BMI
     */
    @Column(name = "height_weight_bmi")
    private Float heightWeightBmi;

    /**
     * 体脂率
     */
    @Column(name = "height_weight_body_fat")
    private Float heightWeightBodyFat;

    /**
     * 备注
     */
    @Column(name = "height_weight_remark")
    private String heightWeightRemark;

    /**
     * 记录类型, 0-打卡, 1-建档
     */
    private Integer heightWeightRecordArchiveTag;

    @Column(name = "create_time")
    private Date createTime;

    @Column(name = "is_del")
    @TableLogic
    private Integer isDel;

    /**
     * 照片以 竖线 | 拼接
     */
    @Column(name = "record_photo")
    private String recordPhoto;

    public Integer getHeightWeightRecordArchiveTag() {
        return heightWeightRecordArchiveTag;
    }

    public void setHeightWeightRecordArchiveTag(Integer heightWeightRecordArchiveTag) {
        this.heightWeightRecordArchiveTag = heightWeightRecordArchiveTag;
    }

    /**
     * @return data_id
     */
    public Integer getDataId() {
        return dataId;
    }

    /**
     * @param dataId
     */
    public void setDataId(Integer dataId) {
        this.dataId = dataId;
    }

    /**
     * @return patient_id
     */
    public Integer getPatientId() {
        return patientId;
    }

    /**
     * @param patientId
     */
    public void setPatientId(Integer patientId) {
        this.patientId = patientId;
    }

    /**
     * 获取记录日期
     *
     * @return record_date - 记录日期
     */
    public Date getRecordDate() {
        return recordDate;
    }

    /**
     * 设置记录日期
     *
     * @param recordDate 记录日期
     */
    public void setRecordDate(Date recordDate) {
        this.recordDate = recordDate;
    }

    /**
     * 获取测量时间
     *
     * @return record_time - 测量时间
     */
    public Date getRecordTime() {
        return recordTime;
    }

    /**
     * 设置测量时间
     *
     * @param recordTime 测量时间
     */
    public void setRecordTime(Date recordTime) {
        this.recordTime = recordTime;
    }

    /**
     * 获取身高
     *
     * @return height_weight_height - 身高
     */
    public Float getHeightWeightHeight() {
        return heightWeightHeight;
    }

    /**
     * 设置身高
     *
     * @param heightWeightHeight 身高
     */
    public void setHeightWeightHeight(Float heightWeightHeight) {
        this.heightWeightHeight = heightWeightHeight;
    }

    /**
     * 获取体重
     *
     * @return height_weight_weight - 体重
     */
    public Float getHeightWeightWeight() {
        return heightWeightWeight;
    }

    /**
     * 设置体重
     *
     * @param heightWeightWeight 体重
     */
    public void setHeightWeightWeight(Float heightWeightWeight) {
        this.heightWeightWeight = heightWeightWeight;
    }

    /**
     * 获取BMI
     *
     * @return height_weight_bmi - BMI
     */
    public Float getHeightWeightBmi() {
        return heightWeightBmi;
    }

    /**
     * 设置BMI
     *
     * @param heightWeightBmi BMI
     */
    public void setHeightWeightBmi(Float heightWeightBmi) {
        this.heightWeightBmi = heightWeightBmi;
    }

    /**
     * 获取体脂率
     *
     * @return height_weight_body_fat - 体脂率
     */
    public Float getHeightWeightBodyFat() {
        return heightWeightBodyFat;
    }

    /**
     * 设置体脂率
     *
     * @param heightWeightBodyFat 体脂率
     */
    public void setHeightWeightBodyFat(Float heightWeightBodyFat) {
        this.heightWeightBodyFat = heightWeightBodyFat;
    }

    /**
     * 获取备注
     *
     * @return height_weight_remark - 备注
     */
    public String getHeightWeightRemark() {
        return heightWeightRemark;
    }

    /**
     * 设置备注
     *
     * @param heightWeightRemark 备注
     */
    public void setHeightWeightRemark(String heightWeightRemark) {
        this.heightWeightRemark = heightWeightRemark;
    }

    /**
     * @return create_time
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @param createTime
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @return is_del
     */
    public Integer getIsDel() {
        return isDel;
    }

    /**
     * @param isDel
     */
    public void setIsDel(Integer isDel) {
        this.isDel = isDel;
    }

    /**
     * 获取照片以 竖线 | 拼接
     *
     * @return record_photo - 照片以 竖线 | 拼接
     */
    public String getRecordPhoto() {
        return recordPhoto;
    }

    /**
     * 设置照片以 竖线 | 拼接
     *
     * @param recordPhoto 照片以 竖线 | 拼接
     */
    public void setRecordPhoto(String recordPhoto) {
        this.recordPhoto = recordPhoto;
    }

    public Integer getRecordType() {
        return recordType;
    }

    public void setRecordType(Integer recordType) {
        this.recordType = recordType;
    }

    public DtrdEntRdSigninHeightWeight init() {
        this.isDel = 0;
        createTime = new Date();
        return this;
    }

    public DtrdEntRdSigninHeightWeight parseFromDTO(HeightBean dto) {
        this.setDataId(dto.getId());
        this.setPatientId(dto.getPatientId());
        this.setHeightWeightHeight(dto.getHeight());
        this.setHeightWeightWeight(dto.getWeight());
        try {
            if (dto.getTime() != null) {
                this.setRecordDate(DateUtils.parseDate(dto.getTime(), DateUtils.date_sdf.get().toPattern()));
                this.setRecordTime(DateUtils.parseDate(dto.getTime(), DateUtils.datetimeFormat.get().toPattern()));
            }
        } catch (ParseException e) {
            log.error("DtrdEntSigninHeightWeight.parseFromDTO 时间转换失败: {}" + dto.getTime());
            e.printStackTrace();
        }
        this.setHeightWeightBmi(SchemeUtil.getBmi(this.getHeightWeightHeight(), this.getHeightWeightWeight()));
        this.setHeightWeightBodyFat(dto.getBodyFat());
        this.setHeightWeightRemark(dto.getRemark());
        this.setRecordPhoto(dto.getRecordPhoto());
        recordType = dto.getStatus();
        return this;
    }
}